package com.action;

import java.util.List;

import com.Entity.User;
import com.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Controller;



import com.opensymphony.xwork2.ActionContext;

@Controller()

@Scope("prototype")

public class RegisterAction {

@SuppressWarnings("unused")

@Autowired

private UserService userService;

private User user;

public User getUser() {

        return user;

        }

        public void setUser(User user) {

        this.user = user;

        }

public String execute() {

        if (user.getAge()>100) {

        throw new AgeException("年龄不符合要求");

        }

        userService.addUser(user);

        return"success";

        }

public String updateUser() {



        userService.updateUser(user);



        return"success";

        }

public String deleteUser() {



        userService.deleteUser(user);



        return"success";

        }

public String queryUsers() {

        List<User> lsit=   userService.queryUsers();

        ActionContext ctx= ActionContext.getContext();

        ctx.put("list", lsit); //表示request对象,ctx.getSession();

        //这个方法可以得到session的东西，但是没有得到session对象，可以对此进行put,ctx.getSession().get(key)可以获取session中对象

        //Map map=

        return"success";

        }

public String getById() {

        User u= userService.getById(user.getId());

        ActionContext ctx= ActionContext.getContext();

        ctx.put("u", u); //表示request对象,ctx.getSession();

        return"success";

        }

        }